<!doctype html>
<html lang="zh">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width,initial-scale=1">
  <title>{{ title or '登录' }} · {{ CONF.get('DEFAULT_COMPANY_NAME','') }}</title>
  <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet">
  <style>
    body{background:#f5f7fa}
    .login-card{max-width:420px;margin:8vh auto;padding:32px;border-radius:18px;box-shadow:0 10px 30px rgba(17,24,39,.08);background:#fff}
    .brand{font-weight:700;letter-spacing:.3px}
  </style>
</head>
<body>
  <div class="login-card">
    <h4 class="mb-1 brand text-center">{{ title or '登录' }}</h4>
    <p class="text-muted text-center mb-4">欢迎回来</p>

    {# 全局提示/错误 #}
    {% with messages = get_flashed_messages(with_categories=true) %}
      {% if messages %}
        {% for cat, msg in messages %}
          <div class="alert alert-{{cat}} mb-3">{{ msg|safe }}</div>
        {% endfor %}
      {% endif %}
    {% endwith %}

    <form method="post" action="{{ post_url }}" novalidate id="loginForm">
      {{ form.hidden_tag() }}

      <div class="mb-3">
        <label class="form-label">用户名</label>
        {{ form.username_or_email(class="form-control form-control-lg", placeholder="用户名 / 邮箱") }}
        {% for e in form.username_or_email.errors %}<div class="text-danger small mt-1">{{ e }}</div>{% endfor %}
      </div>

      <div class="mb-2">
        <label class="form-label">密码</label>
        {{ form.password(class="form-control form-control-lg", placeholder="密码") }}
        {% for e in form.password.errors %}<div class="text-danger small mt-1">{{ e }}</div>{% endfor %}
      </div>

      <input type="hidden" name="next" value="{{ request.args.get('next','') }}">

      <div class="d-grid mt-3">
        <button type="submit" class="btn btn-primary btn-lg" id="submitBtn">登录</button>
      </div>
    </form>

    <div class="text-center text-muted small mt-3">
      若无法登录：清空缓存/换浏览器再试
    </div>
  </div>

  <script>
    // 防止重复点击
    const form = document.getElementById('loginForm');
    const btn  = document.getElementById('submitBtn');
    form.addEventListener('submit', () => { btn.disabled = true; btn.innerText = '登录中...'; });
  </script>
</body>
</html>
